import query from '@dfeidao/atom-nodejs/db/query';
import format from '@dfeidao/atom-nodejs/dt/format';
import { IncomingHttpHeaders } from 'http';
// import { Tracing } from 'trace_events';
import { systemid } from '../atom/config';

interface Message {
	filter: {
		job_no: string;
	};
	page_size: number;
	page_no: number;
	productid: string;
}

interface IWebResult {
	dataArray: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string[];
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(msg: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {

	const { prepare: p, exec: e } = await query(action_id, session_id, systemid);
	// 1.依据"作业编号" 查询<作业>表得到"个性化设置" “班级名称” “作业名称” “作业内容”,
	p('task', ['job_no', 'quote_job_name', 'contents_homework', 'personalized_setting', 'class_name', 'class_id', 'create_time'], { job_no: msg.filter.job_no, productid: msg.productid }, 200, 1, [], []);
	const [data] = await e<{ headimg: string, count: number, create_time: number, c_time: string }>();
	data.forEach(
		(a) => {
			a.c_time = format(a.create_time, 'YYYY/MM/DD');
		}
	);

	return { dataArray: data } as IWebResult;
}
